home *** CD-ROM | disk | FTP | other *** search
/ Isometric Game Programming with DirectX 7.0 / Isometric Game Programming.iso / source / chapter16 / isohex16_3 / isohex16_3.cpp < prev    next >
C/C++ Source or Header  |  2000-08-11  |  17KB  |  600 lines

  1. /*****************************************************************************
  2. IsoHex16_3.cpp
  3. Ernest S. Pazera
  4. 11AUG2000
  5. Start a WIN32 Application Workspace, add in this file
  6. Requires the following libs:
  7. ddraw.lib, dxguid.lib
  8. Requires the following files:
  9. DDFuncs.h.cpp, GDICanvas.h/cpp, IsoMouseMap.h/cpp,
  10. IsoScroller.h/cpp, IsoTilePlotter.h/cpp, IsoTileWalker.h/cpp
  11. TileSet.h/cpp. IsoHexCore.h, IsoHexDefs.h
  12. *****************************************************************************/
  13.  
  14. //////////////////////////////////////////////////////////////////////////////
  15. //INCLUDES
  16. //////////////////////////////////////////////////////////////////////////////
  17. #define WIN32_LEAN_AND_MEAN  
  18.  
  19. #include <windows.h>  
  20. #include "DDFuncs.h"
  21. #include "TileSet.h"
  22. #include "IsoHexCore.h"
  23.  
  24.  
  25. //////////////////////////////////////////////////////////////////////////////
  26. //DEFINES
  27. //////////////////////////////////////////////////////////////////////////////
  28. //name for our window class
  29. #define WINDOWCLASS "ISOHEX16"
  30. //title of the application
  31. #define WINDOWTITLE "IsoHex 16-3"
  32.  
  33. const int MAPWIDTH=200;
  34. const int MAPHEIGHT=400;
  35.  
  36. //////////////////////////////////////////////////////////////////////////////
  37. //PROTOTYPES
  38. //////////////////////////////////////////////////////////////////////////////
  39. bool Prog_Init();//game data initalizer
  40. void Prog_Loop();//main game loop
  41. void Prog_Done();//game clean up
  42.  
  43. //////////////////////////////////////////////////////////////////////////////
  44. //GLOBALS
  45. //////////////////////////////////////////////////////////////////////////////
  46. HINSTANCE hInstMain=NULL;//main application handle
  47. HWND hWndMain=NULL;//handle to our main window
  48.  
  49. //directdraw
  50. LPDIRECTDRAW7 lpdd=NULL;
  51. LPDIRECTDRAWSURFACE7 lpddsMain=NULL;
  52. LPDIRECTDRAWSURFACE7 lpddsBack=NULL;
  53. LPDIRECTDRAWCLIPPER lpddClip=NULL;
  54.  
  55. //tilesets
  56. CTileSet tsBack;//background
  57. CTileSet tsShadow;//tree shadow
  58. CTileSet tsTree;//tree foreground
  59. CTileSet tsCursor;//cursor
  60.  
  61. //isohexcore components
  62. CTilePlotter TilePlotter;//plotter
  63. CTileWalker TileWalker;//walker
  64. CScroller Scroller;//scroller
  65. CMouseMap MouseMap;//mousemap
  66.  
  67. POINT ptCursor;//keep track of the cursor
  68. POINT ptScroll;//keep track of how quickly we scroll
  69.  
  70. int iMap[MAPWIDTH][MAPHEIGHT];//map array(0=no tree, 1=tree)
  71.  
  72. //////////////////////////////////////////////////////////////////////////////
  73. //WINDOWPROC
  74. //////////////////////////////////////////////////////////////////////////////
  75. LRESULT CALLBACK TheWindowProc(HWND hwnd,UINT uMsg,WPARAM wParam,LPARAM lParam)
  76. {
  77.     //which message did we get?
  78.     switch(uMsg)
  79.     {
  80.     case WM_KEYDOWN:
  81.         {
  82.             switch(wParam)
  83.             {
  84.             case VK_ESCAPE:
  85.                 {
  86.                     DestroyWindow(hWndMain);
  87.                     return(0);
  88.                 }break;
  89.             }
  90.         }break;
  91.     case WM_LBUTTONDOWN:
  92.         {
  93.             //change the status of the map
  94.             iMap[ptCursor.x][ptCursor.y]=1-iMap[ptCursor.x][ptCursor.y];
  95.             return(0);
  96.         }break;
  97.     case WM_MOUSEMOVE:
  98.         {
  99.             //grab mouse x and y
  100.             int x=LOWORD(lParam);
  101.             int y=HIWORD(lParam);
  102.  
  103.             //reset scrolling speeds to zero
  104.             ptScroll.x=0;
  105.             ptScroll.y=0;
  106.  
  107.             //left scroll?
  108.             if(x<8) ptScroll.x=x-8;
  109.  
  110.             //upward scroll?
  111.             if(y<8) ptScroll.y=y-8;
  112.  
  113.             //right scroll?
  114.             if(x>=632) ptScroll.x=x-632;
  115.  
  116.             //downward scroll?
  117.             if(y>=472) ptScroll.y=y-472;
  118.         }break;
  119.     case WM_DESTROY://the window is being destroyed
  120.         {
  121.  
  122.             //tell the application we are quitting
  123.             PostQuitMessage(0);
  124.  
  125.             //handled message, so return 0
  126.             return(0);
  127.  
  128.         }break;
  129.     case WM_PAINT://the window needs repainting
  130.         {
  131.             //a variable needed for painting information
  132.             PAINTSTRUCT ps;
  133.             
  134.             //start painting
  135.             HDC hdc=BeginPaint(hwnd,&ps);
  136.  
  137.             /////////////////////////////
  138.             //painting code would go here
  139.             /////////////////////////////
  140.  
  141.             //end painting
  142.             EndPaint(hwnd,&ps);
  143.                         
  144.             //handled message, so return 0
  145.             return(0);
  146.         }break;
  147.     }
  148.  
  149.     //pass along any other message to default message handler
  150.     return(DefWindowProc(hwnd,uMsg,wParam,lParam));
  151. }
  152.  
  153.  
  154. //////////////////////////////////////////////////////////////////////////////
  155. //WINMAIN
  156. //////////////////////////////////////////////////////////////////////////////
  157. int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
  158. {
  159.     //assign instance to global variable
  160.     hInstMain=hInstance;
  161.  
  162.     //create window class
  163.     WNDCLASSEX wcx;
  164.  
  165.     //set the size of the structure
  166.     wcx.cbSize=sizeof(WNDCLASSEX);
  167.  
  168.     //class style
  169.     wcx.style=CS_OWNDC | CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
  170.  
  171.     //window procedure
  172.     wcx.lpfnWndProc=TheWindowProc;
  173.  
  174.     //class extra
  175.     wcx.cbClsExtra=0;
  176.  
  177.     //window extra
  178.     wcx.cbWndExtra=0;
  179.  
  180.     //application handle
  181.     wcx.hInstance=hInstMain;
  182.  
  183.     //icon
  184.     wcx.hIcon=LoadIcon(NULL,IDI_APPLICATION);
  185.  
  186.     //cursor
  187.     wcx.hCursor=LoadCursor(NULL,IDC_ARROW);
  188.  
  189.     //background color
  190.     wcx.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH);
  191.  
  192.     //menu
  193.     wcx.lpszMenuName=NULL;
  194.  
  195.     //class name
  196.     wcx.lpszClassName=WINDOWCLASS;
  197.  
  198.     //small icon
  199.     wcx.hIconSm=NULL;
  200.  
  201.     //register the window class, return 0 if not successful
  202.     if(!RegisterClassEx(&wcx)) return(0);
  203.  
  204.     //create main window
  205.     hWndMain=CreateWindowEx(0,WINDOWCLASS,WINDOWTITLE, WS_POPUP | WS_VISIBLE,0,0,320,240,NULL,NULL,hInstMain,NULL);
  206.  
  207.     //error check
  208.     if(!hWndMain) return(0);
  209.  
  210.     //if program initialization failed, then return with 0
  211.     if(!Prog_Init()) return(0);
  212.  
  213.     //message structure
  214.     MSG msg;
  215.  
  216.     //message pump
  217.     for(;;)    
  218.     {
  219.         //look for a message
  220.         if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  221.         {
  222.             //there is a message
  223.  
  224.             //check that we arent quitting
  225.             if(msg.message==WM_QUIT) break;
  226.             
  227.             //translate message
  228.             TranslateMessage(&msg);
  229.  
  230.             //dispatch message
  231.             DispatchMessage(&msg);
  232.         }
  233.  
  234.         //run main game loop
  235.         Prog_Loop();
  236.     }
  237.     
  238.     //clean up program data
  239.     Prog_Done();
  240.  
  241.     //return the wparam from the WM_QUIT message
  242.     return(msg.wParam);
  243. }
  244.  
  245. //////////////////////////////////////////////////////////////////////////////
  246. //INITIALIZATION
  247. //////////////////////////////////////////////////////////////////////////////
  248. bool Prog_Init()
  249. {
  250.     //create IDirectDraw object
  251.     lpdd=LPDD_Create(hWndMain,DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN | DDSCL_ALLOWREBOOT);
  252.  
  253.     //set display mode
  254.     lpdd->SetDisplayMode(640,480,16,0,0);
  255.  
  256.     //create primary surface
  257.     lpddsMain=LPDDS_CreatePrimary(lpdd,1);
  258.  
  259.     //get back buffer
  260.     lpddsBack=LPDDS_GetSecondary(lpddsMain);
  261.  
  262.     //create clipper
  263.     lpdd->CreateClipper(0,&lpddClip,NULL);
  264.  
  265.     //associate window with the clipper
  266.     lpddClip->SetHWnd(0,hWndMain);
  267.  
  268.     //attach clipper to back buffer
  269.     lpddsBack->SetClipper(lpddClip);
  270.  
  271.     //load in the mousemap
  272.     MouseMap.Load("MouseMap.bmp");
  273.  
  274.     //set up the tile plotter
  275.     TilePlotter.SetMapType(ISOMAP_DIAMOND);//diamond mode
  276.     TilePlotter.SetTileSize(MouseMap.GetWidth(),MouseMap.GetHeight());//grab width and height from mousemap
  277.  
  278.     //set up tile walker to diamond mode
  279.     TileWalker.SetMapType(ISOMAP_DIAMOND);
  280.  
  281.     //set up screeen space
  282.     RECT rcTemp;
  283.     SetRect(&rcTemp,0,0,640,480);
  284.     Scroller.SetScreenSpace(&rcTemp);
  285.  
  286.     //load in tiles and cursor
  287.     tsBack.Load(lpdd,"backgroundts.bmp");
  288.     tsShadow.Load(lpdd,"treeshadowts.bmp");
  289.     tsTree.Load(lpdd,"treets.bmp");
  290.     tsCursor.Load(lpdd,"cursor.bmp");
  291.  
  292.     //grab tile extent from tileset
  293.     CopyRect(&rcTemp,&tsBack.GetTileList()[0].rcDstExt);
  294.  
  295.     //calculate the worldspace
  296.     Scroller.CalcWorldSpace(&TilePlotter,&rcTemp,MAPWIDTH,MAPHEIGHT);
  297.  
  298.     //calculate the mousemap reference point
  299.     MouseMap.CalcReferencePoint(&TilePlotter,&rcTemp);
  300.  
  301.     //calculate anchor space
  302.     Scroller.AdjustWorldSpace(MouseMap.GetWidth()/2,MouseMap.GetHeight()/2,-MouseMap.GetWidth()/2,-MouseMap.GetHeight()/2);
  303.     Scroller.CalcAnchorSpace();
  304.  
  305.     //set wrap modes for scroller
  306.     Scroller.SetHWrapMode(WRAPMODE_CLIP);
  307.     Scroller.SetVWrapMode(WRAPMODE_CLIP);
  308.  
  309.     //set scroller anchor to (0,0)
  310.     Scroller.GetAnchor()->x=0;
  311.     Scroller.GetAnchor()->y=0;
  312.  
  313.     //attach scrolelr and tilewalker to mousemap
  314.     MouseMap.SetScroller(&Scroller);
  315.     MouseMap.SetTileWalker(&TileWalker);
  316.  
  317.     //set up the map to a random tilefield
  318.     for(int x=0;x<MAPWIDTH;x++)
  319.     {
  320.         for(int y=0;y<MAPHEIGHT;y++)
  321.         {
  322.             iMap[x][y]=rand()%2;
  323.         }
  324.     }
  325.  
  326.     return(true);//return success
  327. }
  328.  
  329. //////////////////////////////////////////////////////////////////////////////
  330. //CLEANUP
  331. //////////////////////////////////////////////////////////////////////////////
  332. void Prog_Done()
  333. {
  334.     //release main/back surfaces
  335.     LPDDS_Release(&lpddsMain);
  336.  
  337.     //release clipper
  338.     LPDDCLIP_Release(&lpddClip);
  339.  
  340.     //release directdraw
  341.     LPDD_Release(&lpdd);
  342. }
  343.  
  344. //////////////////////////////////////////////////////////////////////////////
  345. //MAIN GAME LOOP
  346. //////////////////////////////////////////////////////////////////////////////
  347. void Prog_Loop()
  348. {
  349.     //clear out backbuffer
  350.     DDBLTFX ddbltfx;
  351.     DDBLTFX_ColorFill(&ddbltfx,0);
  352.     lpddsBack->Blt(NULL,NULL,NULL,DDBLT_WAIT | DDBLT_COLORFILL,&ddbltfx);
  353.     
  354.     //move the anchor based on scrolling speed
  355.     Scroller.MoveAnchor(ptScroll.x,ptScroll.y);
  356.  
  357.     //grab the mouse position
  358.     POINT ptMouse;
  359.     GetCursorPos(&ptMouse);
  360.     //map the mouse
  361.     ptCursor=MouseMap.MapMouse(ptMouse);
  362.  
  363.     //clip the cursor to valid map coordinates
  364.     if(ptCursor.x<0) ptCursor.x=0;
  365.     if(ptCursor.y<0) ptCursor.y=0;
  366.     if(ptCursor.x>(MAPWIDTH-1)) ptCursor.x=MAPWIDTH-1;
  367.     if(ptCursor.y>(MAPHEIGHT-1)) ptCursor.y=MAPHEIGHT-1;
  368.  
  369.     //the corner map locations of the display
  370.     POINT ptCornerUpperLeft;
  371.     POINT ptCornerUpperRight;
  372.     POINT ptCornerLowerLeft;
  373.     POINT ptCornerLowerRight;
  374.  
  375.     //working variables for calculating corners
  376.     POINT ptScreen;
  377.     POINT ptWorld;
  378.     POINT ptCoarse;
  379.     POINT ptMap;
  380.  
  381.     //calculate upper left corner
  382.     //screen point
  383.     ptScreen.x=Scroller.GetScreenSpace()->left;
  384.     ptScreen.y=Scroller.GetScreenSpace()->top;
  385.     //change into world coordinate
  386.     ptWorld=Scroller.ScreenToWorld(ptScreen);
  387.     //adjust by mousemap reference point    
  388.     ptWorld.x-=MouseMap.GetReferencePoint()->x;
  389.     ptWorld.y-=MouseMap.GetReferencePoint()->y;
  390.     //calculate coarse coordinates
  391.     ptCoarse.x=ptWorld.x/MouseMap.GetWidth();
  392.     ptCoarse.y=ptWorld.y/MouseMap.GetHeight();
  393.     //adjust for negative remainders
  394.     if(ptWorld.x%MouseMap.GetWidth()<0) ptCoarse.x--;
  395.     if(ptWorld.y%MouseMap.GetHeight()<0) ptCoarse.y--;
  396.     //set map point to 0,0
  397.     ptMap.x=0;
  398.     ptMap.y=0;
  399.     //do eastward tilewalk
  400.     ptMap=TileWalker.TileWalk(ptMap,ISO_EAST);
  401.     ptMap.x*=ptCoarse.x;
  402.     ptMap.y*=ptCoarse.x;
  403.     //assign ptmap to corner point
  404.     ptCornerUpperLeft.x=ptMap.x;
  405.     ptCornerUpperLeft.y=ptMap.y;
  406.     //reset ptmap to 0,0
  407.     ptMap.x=0;
  408.     ptMap.y=0;
  409.     //do southward tilewalk
  410.     ptMap=TileWalker.TileWalk(ptMap,ISO_SOUTH);
  411.     ptMap.x*=ptCoarse.y;
  412.     ptMap.y*=ptCoarse.y;
  413.     //add ptmap to corner point
  414.     ptCornerUpperLeft.x+=ptMap.x;
  415.     ptCornerUpperLeft.y+=ptMap.y;
  416.  
  417.     //calculate upper right corner
  418.     //screen point
  419.     ptScreen.x=Scroller.GetScreenSpace()->right;
  420.     ptScreen.y=Scroller.GetScreenSpace()->top;
  421.     //change into world coordinate
  422.     ptWorld=Scroller.ScreenToWorld(ptScreen);
  423.     //adjust by mousemap reference point    
  424.     ptWorld.x-=MouseMap.GetReferencePoint()->x;
  425.     ptWorld.y-=MouseMap.GetReferencePoint()->y;
  426.     //calculate coarse coordinates
  427.     ptCoarse.x=ptWorld.x/MouseMap.GetWidth();
  428.     ptCoarse.y=ptWorld.y/MouseMap.GetHeight();
  429.     //adjust for negative remainders
  430.     if(ptWorld.x%MouseMap.GetWidth()<0) ptCoarse.x--;
  431.     if(ptWorld.y%MouseMap.GetHeight()<0) ptCoarse.y--;
  432.     //set map point to 0,0
  433.     ptMap.x=0;
  434.     ptMap.y=0;
  435.     //do eastward tilewalk
  436.     ptMap=TileWalker.TileWalk(ptMap,ISO_EAST);
  437.     ptMap.x*=ptCoarse.x;
  438.     ptMap.y*=ptCoarse.x;
  439.     //assign ptmap to corner point
  440.     ptCornerUpperRight.x=ptMap.x;
  441.     ptCornerUpperRight.y=ptMap.y;
  442.     //reset ptmap to 0,0
  443.     ptMap.x=0;
  444.     ptMap.y=0;
  445.     //do southward tilewalk
  446.     ptMap=TileWalker.TileWalk(ptMap,ISO_SOUTH);
  447.     ptMap.x*=ptCoarse.y;
  448.     ptMap.y*=ptCoarse.y;
  449.     //add ptmap to corner point
  450.     ptCornerUpperRight.x+=ptMap.x;
  451.     ptCornerUpperRight.y+=ptMap.y;
  452.  
  453.     //calculate lower left corner
  454.     //screen point
  455.     ptScreen.x=Scroller.GetScreenSpace()->left;
  456.     ptScreen.y=Scroller.GetScreenSpace()->bottom;
  457.     //change into world coordinate
  458.     ptWorld=Scroller.ScreenToWorld(ptScreen);
  459.     //adjust by mousemap reference point    
  460.     ptWorld.x-=MouseMap.GetReferencePoint()->x;
  461.     ptWorld.y-=MouseMap.GetReferencePoint()->y;
  462.     //calculate coarse coordinates
  463.     ptCoarse.x=ptWorld.x/MouseMap.GetWidth();
  464.     ptCoarse.y=ptWorld.y/MouseMap.GetHeight();
  465.     //adjust for negative remainders
  466.     if(ptWorld.x%MouseMap.GetWidth()<0) ptCoarse.x--;
  467.     if(ptWorld.y%MouseMap.GetHeight()<0) ptCoarse.y--;
  468.     //set map point to 0,0
  469.     ptMap.x=0;
  470.     ptMap.y=0;
  471.     //do eastward tilewalk
  472.     ptMap=TileWalker.TileWalk(ptMap,ISO_EAST);
  473.     ptMap.x*=ptCoarse.x;
  474.     ptMap.y*=ptCoarse.x;
  475.     //assign ptmap to corner point
  476.     ptCornerLowerLeft.x=ptMap.x;
  477.     ptCornerLowerLeft.y=ptMap.y;
  478.     //reset ptmap to 0,0
  479.     ptMap.x=0;
  480.     ptMap.y=0;
  481.     //do southward tilewalk
  482.     ptMap=TileWalker.TileWalk(ptMap,ISO_SOUTH);
  483.     ptMap.x*=ptCoarse.y;
  484.     ptMap.y*=ptCoarse.y;
  485.     //add ptmap to corner point
  486.     ptCornerLowerLeft.x+=ptMap.x;
  487.     ptCornerLowerLeft.y+=ptMap.y;
  488.  
  489.     //calculate lower right corner
  490.     //screen point
  491.     ptScreen.x=Scroller.GetScreenSpace()->right;
  492.     ptScreen.y=Scroller.GetScreenSpace()->bottom;
  493.     //change into world coordinate
  494.     ptWorld=Scroller.ScreenToWorld(ptScreen);
  495.     //adjust by mousemap reference point    
  496.     ptWorld.x-=MouseMap.GetReferencePoint()->x;
  497.     ptWorld.y-=MouseMap.GetReferencePoint()->y;
  498.     //calculate coarse coordinates
  499.     ptCoarse.x=ptWorld.x/MouseMap.GetWidth();
  500.     ptCoarse.y=ptWorld.y/MouseMap.GetHeight();
  501.     //adjust for negative remainders
  502.     if(ptWorld.x%MouseMap.GetWidth()<0) ptCoarse.x--;
  503.     if(ptWorld.y%MouseMap.GetHeight()<0) ptCoarse.y--;
  504.     //set map point to 0,0
  505.     ptMap.x=0;
  506.     ptMap.y=0;
  507.     //do eastward tilewalk
  508.     ptMap=TileWalker.TileWalk(ptMap,ISO_EAST);
  509.     ptMap.x*=ptCoarse.x;
  510.     ptMap.y*=ptCoarse.x;
  511.     //assign ptmap to corner point
  512.     ptCornerLowerRight.x=ptMap.x;
  513.     ptCornerLowerRight.y=ptMap.y;
  514.     //reset ptmap to 0,0
  515.     ptMap.x=0;
  516.     ptMap.y=0;
  517.     //do southward tilewalk
  518.     ptMap=TileWalker.TileWalk(ptMap,ISO_SOUTH);
  519.     ptMap.x*=ptCoarse.y;
  520.     ptMap.y*=ptCoarse.y;
  521.     //add ptmap to corner point
  522.     ptCornerLowerRight.x+=ptMap.x;
  523.     ptCornerLowerRight.y+=ptMap.y;
  524.  
  525.     //tilewalk from corners
  526.     ptCornerUpperLeft=TileWalker.TileWalk(ptCornerUpperLeft,ISO_NORTHWEST);
  527.     ptCornerUpperRight=TileWalker.TileWalk(ptCornerUpperRight,ISO_NORTHEAST);
  528.     ptCornerLowerLeft=TileWalker.TileWalk(ptCornerLowerLeft,ISO_SOUTHWEST);
  529.     ptCornerLowerRight=TileWalker.TileWalk(ptCornerLowerRight,ISO_SOUTHEAST);
  530.  
  531.     //main rendering loop
  532.     //vars for rendering loop
  533.     POINT ptCurrent;
  534.     POINT ptRowStart;
  535.     POINT ptRowEnd;
  536.     DWORD dwRowCount=0;
  537.  
  538.     //set up rows
  539.     ptRowStart=ptCornerUpperLeft;
  540.     ptRowEnd=ptCornerUpperRight;
  541.  
  542.     //start rendering loops
  543.     for(;;)//"infinite" loop
  544.     {
  545.         //set current point to rowstart
  546.         ptCurrent=ptRowStart;
  547.  
  548.         //render a row of tiles
  549.         for(;;)//'infinite' loop
  550.         {
  551.  
  552.             //check for valid point. if valid, render
  553.             if(ptCurrent.x>=0 && ptCurrent.y>=0 && ptCurrent.x<MAPWIDTH && ptCurrent.y<MAPHEIGHT)
  554.             {
  555.                 //valid, so render
  556.                 ptScreen=TilePlotter.PlotTile(ptCurrent);//plot tile
  557.                 ptScreen=Scroller.WorldToScreen(ptScreen);//world->screen
  558.                 tsBack.PutTile(lpddsBack,ptScreen.x,ptScreen.y,0);//put background tile
  559.                 if(iMap[ptCurrent.x][ptCurrent.y])//check for tree
  560.                 {
  561.                     tsShadow.PutTile(lpddsBack,ptScreen.x,ptScreen.y,0);//put shadow
  562.                     tsTree.PutTile(lpddsBack,ptScreen.x,ptScreen.y,0);//put tree
  563.                 }
  564.             }
  565.             
  566.             //check if at end of row. if we are, break out of inner loop
  567.             if(ptCurrent.x==ptRowEnd.x && ptCurrent.y==ptRowEnd.y) break;
  568.  
  569.             //walk east to next tile
  570.             ptCurrent=TileWalker.TileWalk(ptCurrent,ISO_EAST);
  571.         }
  572.  
  573.         //check to see if we are at the last row. if we are, break out of loop
  574.         if(ptRowStart.x==ptCornerLowerLeft.x && ptRowStart.y==ptCornerLowerLeft.y) break;
  575.  
  576.         //move the row start and end points, based on the row number
  577.         if(dwRowCount&1)
  578.         {
  579.             //odd
  580.             //start moves SW, end moves SE
  581.             ptRowStart=TileWalker.TileWalk(ptRowStart,ISO_SOUTHWEST);
  582.             ptRowEnd=TileWalker.TileWalk(ptRowEnd,ISO_SOUTHEAST);
  583.         }
  584.         else
  585.         {
  586.             //even
  587.             //start moves SE, end moves SW
  588.             ptRowStart=TileWalker.TileWalk(ptRowStart,ISO_SOUTHEAST);
  589.             ptRowEnd=TileWalker.TileWalk(ptRowEnd,ISO_SOUTHWEST);
  590.         }
  591.  
  592.         //increase the row number
  593.         dwRowCount++;
  594.     }
  595.  
  596.     //flip to show the back buffer
  597.     lpddsMain->Flip(0,DDFLIP_WAIT);
  598. }
  599.  
  600.